<include file="public/layout"/>
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>会员管理</h3>
                <h5>网站系统会员索引与管理</h5>
            </div>
        </div>
    </div>
    <!-- 操作说明 -->
    <div id="explanation" class="explanation"
         style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;">
        <div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>
            <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
            <span title="收起提示" id="explanationZoom" style="display: block;"></span>
        </div>
        <ul>
            <li>会员列表管理, 可以给会员群发站内信、邮件等.</li>
            <li>分销系统可以查看会员上下级信息.</li>
        </ul>
    </div>
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>会员列表</h3>
                <h5>(共<span id="user_count"></span>条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" id="search-form2" onsubmit="return false">
                <input type="hidden" name="tpl" value="ajaxindex_married">
                <input type="hidden" name="order_by" value="user_id">
                <input type="hidden" name="sort" value="desc">
                <input type="hidden" name="mobile" value="" id="input-mobile"/>
                <input type="hidden" name="email" value="" id="input-email"/>
                <!--分销时查看下级人数都有哪些-->
                <input type="hidden" name="first_leader" value="{$_GET['first_leader']}">
                <input type="hidden" name="second_leader" value="{$_GET['second_leader']}">
                <input type="hidden" name="third_leader" value="{$_GET['third_leader']}">
                <div class="sDiv">

                    <div class="sDiv2">
                        <select name="autoF" class="select sDiv3" style="margin-right:5px;margin-left:5px">
                            <option value="">分配状态</option>
                            <option value="1">已经分配</option>
                            <option value="0">没有分配</option>
                        </select>
                    </div>

                    <div class="sDiv2">
                        <input type="text" id="search_key" size="30" class="qsbox" placeholder="新娘电话">
                        <input type="submit" class="btn" onclick="ajax_get_table('search-form2',1)" value="搜索">
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="sign" axis="col0">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </th>
                        <th align="left" abbr="user_id" axis="col3" class="">
                            <div style="text-align: center; width: 40px;" class="">ID</div>
                        </th>
                        <th align="left" abbr="nickname" axis="col4" class="">
                            <div style="text-align: center; width: 150px;" class="">新娘/新郎</div>
                        </th>
                        <th align="center" abbr="level" axis="col5" class="">
                            <div style="text-align: center; width: 150px;" class="">新娘电话</div>
                        </th>
                        <th align="center" abbr="total_amount" axis="col6" class="">
                            <div style="text-align: center; width: 150px;" class="">新郎电话</div>
                        </th>

                        <th align="center" abbr="mobile" axis="col6" class="">
                            <div style="text-align: center; width: 80px;" class="">结婚日期</div>
                        </th>

                        <th align="center" abbr="reg_time" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">订单价格</div>
                        </th>
                        <th align="center" abbr="is_counselor" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">订单编号</div>
                        </th>
                        <th align="center" abbr="is_counselor" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">套餐名称</div>
                        </th>

                        <th align="center" abbr="is_counselor" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">是否自动分配</div>
                        </th>

                        <th align="center" abbr="is_counselor" axis="col6" class="">
                            <div style="text-align: center; width: 120px;" class="">分配人员</div>
                        </th>


                        <th align="center" axis="col1" class="">
                            <div style="text-align: center; width: 300px;">操作</div>
                        </th>
                        <th style="width:100%" axis="col7">
                            <div></div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton">
                    <a href="{:U('Married/married_order')}">
                        <div class="add" title="添加会员">
                            <span><i class="fa fa-plus"></i>添加订单</span>
                        </div>
                    </a>
                </div>

                <div class="fbutton">
                    <a href="javascript:;" onclick="publicAutoOrder('auto')">
                        <div class="add" title="批量分配">
                            <span>批量分配</span>
                        </div>
                    </a>
                </div>


            </div>
            <div style="clear:both"></div>
        </div>
        <div class="bDiv" style="height: auto;" id="ajax_return">
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        // 点击刷新数据
        var ssort = 'sdesc';
        var on_sclick = 0;
        $('.hDivBox > table>thead>tr>th').hover(
            function () {
                if (typeof($(this).attr('abbr')) == "undefined") {
                    return false;
                }
                $(this).addClass('thOver');
                if ($(this).hasClass('sorted')) {
                    if (ssort == 'sdesc') {
                        $(this).find('div').removeClass('sdesc');
                        $(this).find('div').addClass('sasc');
                    } else {
                        $(this).find('div').removeClass('sasc');
                        $(this).find('div').addClass('sdesc');
                    }
                } else {
                    $(this).find('div').addClass(ssort);
                }
            }, function () {
                if (typeof($(this).attr('abbr')) == "undefined") {
                    return false;
                }
                if (on_sclick == 0) {
                    if ($(this).hasClass('sorted')) {
                        if (ssort == 'sdesc') {
                            $(this).find('div').removeClass('sasc');
                            $(this).find('div').addClass('sdesc');
                        } else {
                            $(this).find('div').removeClass('sdesc');
                            $(this).find('div').addClass('sasc');
                        }
                    } else {
                        $(this).find('div').removeClass(ssort);
                    }
                }
                $(this).removeClass("thOver");
                on_sclick = 0;
            }
        );
        $('.hDivBox > table>thead>tr>th').click(function () {
            if (typeof($(this).attr('abbr')) == "undefined") {
                return false;
            }
            if ($(this).hasClass('sorted')) {
                $(this).find('div').removeClass(ssort);
                if (ssort == 'sdesc') {
                    ssort = 'sasc';
                } else {
                    ssort = 'sdesc';
                }
                $(this).find('div').addClass(ssort);
                on_sclick = 1;
            } else {
                $('.hDivBox > table>thead>tr>th').removeClass('sorted');
                $('.hDivBox > table>thead>tr>th').find('div').removeClass(ssort);
                $(this).addClass('sorted');
                $(this).find('div').addClass(ssort);
                var hDivBox_th_index = $(this).index();
                var flexigrid_tr = $('#flexigrid > table>tbody>tr')
                flexigrid_tr.each(function () {
                    $(this).find('td').removeClass('sorted');
                    $(this).children('td').eq(hDivBox_th_index).addClass('sorted');
                });
            }
            sort($(this).attr('abbr'));
        });

        $('.fa-refresh').click(function () {
            location.href = location.href;
        });
        ajax_get_table('search-form2', 1);

    });
    //选中全部
    $('.hDivBox .sign').click(function () {
        var sign = $('#flexigrid > table>tbody>tr');
        if ($(this).parent().hasClass('trSelected')) {
            sign.each(function () {
                $(this).removeClass('trSelected');
            });
            $(this).parent().removeClass('trSelected');
        } else {
            sign.each(function () {
                $(this).addClass('trSelected');
            });
            $(this).parent().addClass('trSelected');
        }
    })

    // ajax 抓取页面
    function ajax_get_table(tab, page) {
        var search_key = $.trim($('#search_key').val());
        if (search_key.length > 0) {
            if (checkEmail(search_key)) {
                $('#input-email').val(search_key);
            } else if (checkMobile(search_key)) {
                $('#input-mobile').val(search_key);
            } else {
                layer.alert('请输入正确的邮箱或者手机号码', {icon: 2});
            }
        }
        cur_page = page; //当前页面 保存为全局变量
        $.ajax({
            type: "POST",
            url: "/index.php/Admin/married/ajaxorder/p/" + page,//+tab,
            data: $('#' + tab).serialize(),// 你的formid
            success: function (data) {
                $("#ajax_return").html('');
                $("#ajax_return").append(data);
            }
        });
    }



    // 点击排序
    function sort(field) {
        $("input[name='order_by']").val(field);
        var v = $("input[name='sort']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='sort']").val(v);
        ajax_get_table('search-form2', cur_page);
    }
    /**
     * 回调函数
     */
    function call_back(v) {
        layer.closeAll();
        if (v == 1) {
            layer.msg('发送成功', {icon: 1});
        } else {
            layer.msg('发送失败', {icon: 2});
        }
    }

    function publicAutoOrder(type){
        var ids = '';
        var money = false;
        $('#flexigrid .trSelected').each(function(i,o){
//            ids.push($(o).data('id'));
            if($(o).data('money') >= 50000 ){
                money = true;
            }
            ids += $(o).data('id')+',';
        });
        if(ids == ''){
            layer.msg('至少选择一项', {icon: 2, time: 2000});
            return false;
        }
        if(money){
            layer.msg('订单金额超过【5万】不能自动分配', {icon: 2, time: 2000});
            return false;
        }
        console.log(ids);
        $.ajax({
            type: "POST",
            url: "{:U('Admin/married/autoAllOrder')}",
            data: {ids:ids},// 你的formid
            dataType:'json',
            success: function (data) {
                layer.msg('成功分配【'+data.result.success+'】 失败【'+data.result.faild+'】', {icon: 1, time: 3000},function () {
                    location.href = "{:U('Admin/Married/order_index')}";
                });
            }
        });
    }

</script>
</body>
</html>